package controller;

import dao.IHisDataDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import service.PerformanceBaseDadaServiceOne;
import service.PerformanceService;

/**
 * Created by lvdouStart on 2017/8/17.
 */
@Component
@EnableScheduling
public class ScheduledTasks {

    private static final Logger logger = LoggerFactory.getLogger(ScheduledTasks.class);

    private static boolean flag = true;

    @Autowired
    PerformanceBaseDadaServiceOne performanceBaseDadaServiceOne;

    @Autowired
    PerformanceService performanceService;

    @Autowired
    IHisDataDao hisDataDao;

    /**
     * @Author: 杨青桦
     * @Description: 控江医院分析收入（具体到各设备，收费时间，收费金额）
     * @Date: 2017/11/14 18:08
     */
    @Scheduled(cron = "0 0/15 10-17 * * ?")
    public void setDataExcludePacs() {
        //每次处理5万条pacs记录需要多少次
        int pacs = (int)Math.ceil(hisDataDao.countsPacsHisData()/30000);
        if(pacs != 0){
            performanceBaseDadaServiceOne.setPacsData(null, 30000);
            return;
        }
        //处理完pas记录再处理非pacs的
        int notPacs = (int)Math.ceil(hisDataDao.countsHisDataExcluedPacs()/50000);
        if(pacs == 0 && notPacs != 0 ){
            performanceBaseDadaServiceOne.setDataExcludePacs(null, 50000);
        }

       logger.info(notPacs + " notPacs");
    }

    /**
     * @Author: 杨青桦
     * @Description: 控江医院基础数据分析完后，再将数据分组插到绩效分析表中
     * @Date: 2017/11/14 18:08
     */
    @Scheduled(cron = "0 5 18 * * ?")
    public void setPerformance() {
        performanceService.setPerformance("1474861057500131");
        logger.info("完成");
    }


}